package com.ctvit.struts.action;

import com.ctvit.framework.struts2.ActionSupport;
import com.ctvit.framework.web.context.ContextHolder;
import com.ctvit.sms.platform.service.SubsService;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

/**
 * Created by LoreYun on 2016/1/13.
 */
public class SubsAction extends ActionSupport {
	private SubsService subsService = ContextHolder.getBean(SubsService.class);

	private HashMap msgCategoryJson;

	public void updateToggleStatus() {
		//取userID
//		String str_userID = "00104060";
		//取option
		HttpServletRequest request = ServletActionContext.getRequest();
		String str_toggleLevel = request.getParameter("toggleLevel");
		String str_toggleID = request.getParameter("toggleID");
		String str_status = request.getParameter("status");
		String str_userID = request.getParameter("userID");

		System.out.println(str_toggleLevel);
		System.out.println(str_toggleID);
		System.out.println(str_status);
		System.out.println(str_userID);
		//判断是不是为空
		if (str_status == null || str_status.equals("") || str_toggleID == null || str_toggleID.equals("") || str_toggleLevel == null || str_toggleLevel.equals("")) {
			return;
		}

		if (str_status.equals("ON")) {
			if (str_toggleLevel.equals("1")) {
				subsService.doUpdateAbleStatusByUserIDCate(str_userID, str_toggleID, "0");
			} else if (str_toggleLevel.equals("2")) {
				subsService.doUpdateOpenStatusByUserIDSubcatID(str_userID, str_toggleID, "0");
			} else {
				System.out.println("status : " + str_status + " but wrong Level : " + str_toggleLevel);
			}
		} else if (str_status.equals("OFF")) {
			if (str_toggleLevel.equals("1")) {
				subsService.doUpdateAbleStatusByUserIDCate(str_userID, str_toggleID, "1");
			} else if (str_toggleLevel.equals("2")) {
				subsService.doUpdateOpenStatusByUserIDSubcatID(str_userID, str_toggleID, "1");
			} else {
				System.out.println("status : " + str_status + " but wrong Level : " + str_toggleLevel);
			}
		} else {
			System.out.println("wrong status : " + str_status);
		}
	}

	public String getMsgCat() {
		return "msgCategoryJson";
	}

	public HashMap getMsgCategoryJson() {
		return msgCategoryJson;
	}

	public void setMsgCategoryJson(HashMap msgCategoryJson) {
		this.msgCategoryJson = msgCategoryJson;
	}
}
